/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuP.java
 *
 * Created on 18/01/2012, 03:47:30 PM
 */
package GUI;

//import java.awt.event.MouseEvent;
import Control.*;
import Entidad.Canal;
import Entidad.Emisora;
import Entidad.Funciones;
import Entidad.Usuario;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

//import javax.swing.JTree;
//import javax.swing.tree.TreePath;
/**
 *
 * @author Andrés 2
 */
public class MenuP extends javax.swing.JFrame {

    private Usuario u;
    private Funciones f;

    public Usuario getU() {
        return u;
    }

    public void setU(Usuario u) {
        this.u = u;
    }

    public Funciones getF() {
        return f;
    }

    public void setF(Funciones f) {
        this.f = f;
    }
    private PermisosJpaController controlPermisos = new PermisosJpaController();
    private PanelRadio radios = new PanelRadio();
    private PanelTV television = new PanelTV();
    //  private AdministradorJF Admin = new AdministradorJF();
    private AdminMonitor monitoreador = new AdminMonitor();
//    private AdminCanal canal = new AdminCanal();
    private AdminEmisora emisora = new AdminEmisora();
    private AdministracionCanal canal = new AdministracionCanal();
    private AdminReportes reportes = new AdminReportes();
    public static String Dato = "";

//    void doMouseClicked(MouseEvent me) {
//    TreePath tp = TRadio.getPathForLocation(me.getX(), me.getY());
//    String path = tp.toString().toUpperCase();
//    if (tp != null)
//      jLabel1.setText(path.substring(path.length()/2,path.length()-1));
//    else
//      jLabel1.setText("");
//  }
    /** Creates new form MenuP */
    public MenuP() {
        initComponents();

    }

    public MenuP(Usuario us) {
        initComponents();

             
        EmisoraJpaController emisoraJpaController = new EmisoraJpaController();
        CanalJpaController canalJpaController = new CanalJpaController();
        List list = emisoraJpaController.findEmisoraEntities();
        List list2 = canalJpaController.findCanalEntities();
        TRadio = new javax.swing.JTree();
        TTelevision = new javax.swing.JTree();

        
        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Radio");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("ad");

        for (int i = 0; i < list.size(); i++) {
            Emisora emisora1 = (Emisora) list.get(i);
            treeNode2 = new javax.swing.tree.DefaultMutableTreeNode(emisora1.getNombre());
            treeNode1.add(treeNode2);

        }

        TRadio.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        TRadio.addTreeWillExpandListener(new javax.swing.event.TreeWillExpandListener() {

            public void treeWillCollapse(javax.swing.event.TreeExpansionEvent evt) throws javax.swing.tree.ExpandVetoException {
                TRadioTreeWillCollapse(evt);
            }

            public void treeWillExpand(javax.swing.event.TreeExpansionEvent evt) throws javax.swing.tree.ExpandVetoException {
            }
        });
        TRadio.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TRadioMouseClicked(evt);
            }
        });
        TRadio.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                TRadioValueChanged(evt);
            }
        });

        jScrollPane4.setViewportView(TRadio);
        
        
        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Television");
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("");
        
        for (int i = 0; i < list2.size(); i++) {
            Canal canal1 = (Canal) list2.get(i);
            treeNode2 = new javax.swing.tree.DefaultMutableTreeNode(canal1.getNombre());
            treeNode1.add(treeNode2);

        }

        TTelevision.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        TTelevision.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TTelevisionMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(TTelevision);
        
     

        this.setTitle("SmartBuilderMedia");

        this.u = us;
        this.f = new Funciones();
        this.f.setIdFunciones(1001);
        this.f.setNombre("Administrador");
        if (!controlPermisos.isFuncion(u, f)) {
            this.TAdmin.setVisible(false);
        }
        this.f.setIdFunciones(1002);
        this.f.setNombre("Monitoreador Radio");
        if (!controlPermisos.isFuncion(u, f)) {
            this.TRadio.setVisible(false);
        }
        this.f.setIdFunciones(1003);
        this.f.setNombre("Monitoreador Television");
        if (!controlPermisos.isFuncion(u, f)) {
            this.TTelevision.setVisible(false);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PanelPrincipal = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        TRadio = new javax.swing.JTree();
        jScrollPane5 = new javax.swing.JScrollPane();
        TTelevision = new javax.swing.JTree();
        jScrollPane6 = new javax.swing.JScrollPane();
        TAdmin = new javax.swing.JTree();
        Prueba = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        PanelPrincipal.setLayout(new java.awt.BorderLayout());

        jLabel1.setText("SMART BUILDER MEDIA");

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        TRadio.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        TRadio.addTreeWillExpandListener(new javax.swing.event.TreeWillExpandListener() {
            public void treeWillCollapse(javax.swing.event.TreeExpansionEvent evt)throws javax.swing.tree.ExpandVetoException {
                TRadioTreeWillCollapse(evt);
            }
            public void treeWillExpand(javax.swing.event.TreeExpansionEvent evt)throws javax.swing.tree.ExpandVetoException {
            }
        });
        TRadio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TRadioMouseClicked(evt);
            }
        });
        TRadio.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                TRadioValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(TRadio);

        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Television");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Caracol");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("RCN");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Canal13");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("CityTv");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Mtv");
        treeNode1.add(treeNode2);
        TTelevision.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        TTelevision.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TTelevisionMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(TTelevision);

        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Administrador");
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Usuarios");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Emisoras");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Canales");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Reportes");
        treeNode1.add(treeNode2);
        TAdmin.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        TAdmin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TAdminMouseClicked(evt);
            }
        });
        jScrollPane6.setViewportView(TAdmin);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane6)
                    .addComponent(jScrollPane5)
                    .addComponent(jScrollPane4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(283, 283, 283)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(PanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE))
                            .addComponent(Prueba, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(210, 210, 210))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Prueba, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(PanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TRadioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TRadioMouseClicked
        Dato = String.valueOf(TRadio.getLastSelectedPathComponent());
        PanelPrincipal.setVisible(false);
        PanelPrincipal.removeAll();
        Prueba.setText(Dato);

        PanelPrincipal.add(radios);
        PanelPrincipal.setVisible(true);
        Prueba.setText(Dato);
        radios.setTPendRadio(Dato);
        radios.setTRevRadio(Dato);
        // TODO add your handling code here:
        //agregar la parte de la base de datos conectada a la tabla
}//GEN-LAST:event_TRadioMouseClicked

    private void TTelevisionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TTelevisionMouseClicked

        Dato = String.valueOf(TTelevision.getLastSelectedPathComponent());
        PanelPrincipal.setVisible(false);
        PanelPrincipal.removeAll();
        Prueba.setText(Dato);
        
        PanelPrincipal.add(television);
        PanelPrincipal.setVisible(true);
        Prueba.setText(Dato);
        television.setTablaPendTV(Dato);
        television.setTablaRevTV(Dato);
        // TODO add your handling code here:
    }//GEN-LAST:event_TTelevisionMouseClicked

    private void TAdminMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TAdminMouseClicked
        Prueba.setText("");
        Dato = String.valueOf(TAdmin.getLastSelectedPathComponent());
        if ("Usuarios".equals(Dato)) {
            PanelPrincipal.setVisible(false);
            PanelPrincipal.removeAll();
            PanelPrincipal.add(monitoreador);
            PanelPrincipal.setVisible(true);
        }

        if ("Emisoras".equals(Dato)) {
            PanelPrincipal.setVisible(false);
            PanelPrincipal.removeAll();
            PanelPrincipal.add(emisora);
            PanelPrincipal.setVisible(true);
        }
        if ("Canales".equals(Dato)) {

            PanelPrincipal.setVisible(false);
            PanelPrincipal.removeAll();
            PanelPrincipal.add(canal);
            PanelPrincipal.setVisible(true);
        }

        if ("Reportes".equals(Dato)) {
            PanelPrincipal.setVisible(false);
            PanelPrincipal.removeAll();
            PanelPrincipal.add(reportes);
            PanelPrincipal.setVisible(true);
        }

        // TODO add your handling code here:
    }//GEN-LAST:event_TAdminMouseClicked

    private void TRadioTreeWillCollapse(javax.swing.event.TreeExpansionEvent evt)throws javax.swing.tree.ExpandVetoException {//GEN-FIRST:event_TRadioTreeWillCollapse
        // TODO add your handling code here:
    }//GEN-LAST:event_TRadioTreeWillCollapse

    private void TRadioValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_TRadioValueChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_TRadioValueChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel");
                    // UIManager.("oktoberfest.jpge");
                    //SubstanceImageWatermark("c:\\asd.JPEG");
                    //SubstanceLookAndFeel.WATERMARK_VISIBLE;
                    //org.pushingpixels.substance.api.skin.SubstanceTwilightLookAndFeel
                } catch (Exception e) {
                    System.out.println("Substance Graphite failed to initialize");
                }
                MenuP w = new MenuP();
                w.setVisible(true);
            }
        });
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new MenuP().setVisible(true);
//            }
//        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelPrincipal;
    private javax.swing.JLabel Prueba;
    private javax.swing.JTree TAdmin;
    private javax.swing.JTree TRadio;
    private javax.swing.JTree TTelevision;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    // End of variables declaration//GEN-END:variables
}
